package com.zcx.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author zhaochangxin
 * @Title: MyMetaObjectHandler
 * @Package com.zcx.handler
 * @Description: MyMetaObjectHandler
 * @date 2022/3/30 11:17
 */
@Component
@Slf4j
public class MyMetaObjectHandler implements MetaObjectHandler {
    // 插入时的填充策略
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("start insertFill");
        this.setFieldValByName("createdDate",new Date(),metaObject);
        this.setFieldValByName("lastModified",new Date(),metaObject);
    }
    // 更新时的填充策略
    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("start updateFill");
        this.setFieldValByName("lastModified",new Date(),metaObject);
    }
}
